﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using CSM.Controllers;
using CSM.Models;

namespace CSM
{
    public partial class Login : System.Web.UI.Page
    {
        public string alert = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Expires = -1; //设定当前的页面不保存历史页面。
            SetFocus(this.username0);
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(username0.Text) || string.IsNullOrEmpty(password0.Text))
                return;
            string CheckCode = Session[SystemVars.sysSessionCheckImage].ToString();
            if (CheckCode != CheckCode_Input.Text)
            {
                alert = "<script>alert('验证码不正确');</script>";
                return;

            }
            try
            {
                CSMLogin login = new CSMLogin(username0.Text);
                if (login.CheckPassword(password0.Text) != 0)
                {
                    Response.Write("密码错误!");
                    Response.End();
                }
                if (login.isAccountLock)
                {
                    Response.Write("账户被停用");
                    Response.End();
                }
                login.Enter();
                if (Request.QueryString["redir"] == null)
                    Response.Redirect("~/Default.aspx");
                else
                    Response.Redirect(Request.QueryString["redir"].ToString());
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
                Response.End();
            }
        }
    }
}
